// Michael Depuy
// depuym@onid.orst.edu
// CS311-400
// Homework 4

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

void proc_sigusr1(int signal){

  printf("SIGUSR1 has been caught.\n");
  kill(getpid(),signal);

}

void proc_sigusr2(int signal){
  
  printf("SIGUSR2 has been caught.\n");
  kill(getpid(),signal);

}

void proc_sigint(int signal){

  printf("SIGINT has been caught, terminating the program.\n");
  exit(0);

}

int main(int argc, char *argv[]){

  struct sigaction usr_sig1,usr_sig2,usr_sigint;
  
  usr_sig1.sa_handler = proc_sigusr1;
  usr_sig2.sa_handler = proc_sigusr2;
  usr_sigint.sa_handler = proc_sigint;

  sigaction(SIGUSR1,&usr_sig1,NULL);
  sigaction(SIGUSR2,&usr_sig2,NULL);
  sigaction(SIGINT,&usr_sigint,NULL);

  signal(SIGUSR1,SIG_DFL);
  signal(SIGUSR2,SIG_DFL);
  signal(SIGINT,SIG_DFL);

  for(;;){
    pause();
  }

  return 0;
}
